package com.suse.service.community.config;

import com.suse.service.community.mvc.interceptor.LoginInterceptor;
import com.suse.service.community.mvc.interceptor.MessageInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * <p>
 * MVC配置类
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-08-30 16:03
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Resource
    private MessageInterceptor messageInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截器的顺序按照添加的顺序
        // 登录拦截器
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns(
                    "/**/*.css",
                    "/**/*.js",
                    "/**/*.png",
                    "/**/*.jpg",
                    "/**/*.jpeg"
                );
        // 消息拦截器
        registry.addInterceptor(messageInterceptor)
                .excludePathPatterns(
                    "/**/*.css",
                    "/**/*.js",
                    "/**/*.png",
                    "/**/*.jpg",
                    "/**/*.jpeg"
                );
    }

}
